<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
  <%@ taglib prefix="s" uri="/struts-tags"%>
  <%@ page import="logic.*"%>

<%@ page import="java.sql.PreparedStatement"%>
<%@ page import="java.sql.ResultSet"%>
<%@ page import="java.io.IOException"%>
<%@ page import="java.sql.SQLException"%>

<%
// w celu poprawnie dzialajacej sesji:
response.setHeader("Cache-Control","no-store"); 
response.setHeader("Pragma","no-cache"); 
response.setDateHeader ("Expires", 0); 

String myname =  (String)session.getAttribute("maly"); //pobieramy sesje (login)


%>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Zarzadzanie magazynem</title>
	<link rel="stylesheet" type="text/css" href="css/style.css" media="screen"/>
	<script type="text/javascript" src="js/skrypt.js"></script>
	<link href='http://fonts.googleapis.com/css?family=Open+Sans+Condensed:300&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
</head>
<body>
<div id="glowne">
	<div id="baner">
		<a href="index.jsp"><div class="header"></div></a>
	</div>
	
	<div id="newsy_tresc">
		<div id="menu">
			<ul id="menu">
				
				<li><s:a action="produkt">Zarządzanie Produktem</s:a></li>
				<li><s:a action="show">Aktualny Stan Magazynu</s:a></li>
				<li><s:a action="powiadomienie">Sprawdź co się kończy</s:a></li>
				<li><s:a action="zamowienie">Złóż zamówienie</s:a></li>
				<li><s:a action="rejestrZamowien">Zrealizuj zamówienie</s:a></li>
			</ul>
		</div>
		
		<div id="tresc">
		
		<%
		 if("som".equals(request.getParameter("zulewtaxi"))){
		
String loginF = request.getParameter("loginF");
String passF = request.getParameter("passwordF");

if(loginF.equals("admin") && passF.equals("admin"))
{	
	session.setAttribute("maly", loginF);
	out.println("Zalogowano jako <b>administrator</b><br><a href=index.jsp?admin=yes>Przejdz dalej</a>");
}
else{

boolean check = false;
boolean check1 = false;
boolean check2 = false;
ResultSet result=null;
PreparedStatement preparedStatement=null;
ConnectPRO.connectpro();
preparedStatement = ConnectPRO.connect.prepareStatement("select login, haslo from uzytkownik where login = ? and haslo = ?");
preparedStatement.setString(1, loginF);
preparedStatement.setString(2, passF);
result = preparedStatement.executeQuery();


	if(result != null) {
		while(result.next()){
			                if(loginF.equals(result.getString("login"))) check1 = true;
			                      
			                if(passF.equals(result.getString("haslo"))) check2 = true;
			                }
						} 
	
	if(check1 && check2) check = true;
		

if(check){
	session.setAttribute("maly", loginF);
	
		
		out.println("<br>Witaj <b>" + loginF + "</b><br><a href=\"index.jsp\">back</a>");
		
	
}else
{
	
		out.print("<br>Niepoprawny login lub haslo!<br><a href=\"index.jsp\">back</a>");
	
	
}
}
}

else{
	if(myname == null) LoginPRO2.formularzLogowania(out, "index.jsp?zulewtaxi=som", "../register.jsp");
	
}
%>
		
		
		
		 
							
							
		
		
		
		</div>
			<div id="newsy">
			<p>
				<script> funkcja1();
					funkcja2();
				</script>
			</p>
						
		</div>
		<div id="newsy" style="font-weight: bold;">
			<% if(myname != null){ out.println("<a href=\"wyloguj.jsp\" >"+myname+"<br> wyloguj</a>"); } %>	
			</div>
	</div>
	<div id="stopka">&copy Magazyn v2.0</div>
</div>

</body>
</html>